/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */
import React, { useEffect } from 'react';
import { useState } from 'react';
import type { Node } from 'react';
import {
    SafeAreaView,
    StatusBar,
    Text,
    Button,
    Image,
    View,
} from 'react-native';
import { RTNETBridge } from 'rtn-etbridge';
import { RNMain, RNIat, RNExOcr } from 'mp-native'
const App: () => Node = () => {
    const [result, setResult] = useState<number | null>(null);
    const [uri, setUri] = useState<string>("");
    const [WatermarkUri, setWatermarkUri] = useState<string>("");
    useEffect(() => {
        const subscription = RNIat.addInterfaceBackListener((event) => {
            console.log('event', event);
        });
        return () => {
            subscription.remove();
        };
    }, []);
    return (
        <SafeAreaView>
            <StatusBar barStyle={'dark-content'} />
            {/* <Button
                title="Compute"
                onPress={async () => {
                    const value = await RTNETBridge?.add(1, 1);
                    setResult(value || null);
                }}
            />
            <Button
                title="isPadUsingMobileUIStyle"
                onPress={async () => {
                    const value = await RNMain.isPadUsingMobileUIStyle();
                    console.log('isPadUsingMobileUIStyle', value);
                }}
            />
            <Button
                title="dataToJS"
                onPress={async () => {
                    const value = await RNMain.dataToJS();
                    console.log('dataToJS', value);
                }}
            />
            <Button
                title="toGroupLoginControler"
                onPress={async () => {
                    const value = await RNMain.gotoLogin();
                }}
            />
            <Button
                title="onBackPressed"
                onPress={async () => {
                    const value = await RNMain.onBackPressed();
                }}
            />
            <Button
                title="getRNLayoutInfo"
                onPress={async ()  => {
                    const value = await RNMain.getRNLayoutInfo();
                    console.log('getRNLayoutInfo', value);
                }}
            /> */}
            <View style={{display:'flex',justifyContent:'center', alignItems:'center'}}>
                <Image style={{width: 330, height: 210}} source={{
                        uri:uri,
                        }} />
                <View style={{height:10}}></View>
                <Image style={{width: 330, height: 210}} source={{
                    uri:WatermarkUri,
                }} />
            </View>
            <Button
                title="选择照片"
                onPress={async ()  => {
                    const options = {
                        fileName:"asfaf",
                    }
                    RNExOcr.selectPhoto(options).then((photoFile)=>{
                        setUri(photoFile.uri)
                        console.log(`takePhoto success ${JSON.stringify(photoFile)}`);
                    }).catch((error)=>{ 
                        console.log(`takePhoto error 22222 ${JSON.stringify(error)}`);    
                    });
                }}
            />
            <View style={{height:10}}></View>
            <Button
                title="拍照"
                onPress={async ()  => {
                    const options = {
                        fileName:"asfaf",
                    }
                    RNExOcr.takePhoto(options).then((photoFile)=>{
                        setUri(photoFile.uri)
                        console.log(`takePhoto success ${JSON.stringify(photoFile)}`);
                    }).catch((error)=>{ 
                        console.log(`takePhoto error 22222 ${JSON.stringify(error)}`);    
                    });
                }}
            />
            <View style={{height:10}}></View>
            <Button
                title="水印"
                onPress={async ()  => {
                    const options = {
                        filePath: uri,
                        fileName: "test",
                    }
                    console.log(`options ${JSON.stringify(options)} `)
                    RNExOcr.processWatermarkOCRImageFile(options).then((photoFile)=>{
                        setWatermarkUri(photoFile.uri)
                        console.log(`takePhoto success ${JSON.stringify(photoFile)}`);
                    }).catch((error)=>{ 
                        console.log(`takePhoto error 22222 ${JSON.stringify(error)}`);
                    });
                }}
            />
            <View style={{height:10}}></View>
            <Button
                title="压缩图片"
                onPress={async ()  => {
                    const options = {
                        filePath: uri,
                        fileName: "test",
                    }
                    console.log(`options ${JSON.stringify(options)} `)
                    RNExOcr.processOCRImageFile(options).then((photoFile)=>{
                        setWatermarkUri(photoFile.uri)
                        console.log(`takePhoto success ${JSON.stringify(photoFile)}`);
                    }).catch((error)=>{ 
                        console.log(`takePhoto error 22222 ${JSON.stringify(error)}`);
                    });
                }}
            />
        </SafeAreaView>
    );
};
export default App;